package com.jcj.jcjconfig.demo.controller;

import com.jcj.jcjconfig.demo.config.JcjDemoConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

@RestController
public class DemoController {

    @Value("${jcj.a}")
    private String a;

    @Value("${jcj.b}")
    private String b;

    @Autowired
    private JcjDemoConfig jcjDemoConfig;

    @Autowired
    Environment environment;

    @GetMapping("/demo")
    public String demo() {
        return "jcj.a = " + a + "\n"
                + "jcj.b = " + b + "\n"
                + "demo.a = " + jcjDemoConfig.getA() + "\n"
                + "demo.b = " + jcjDemoConfig.getB() + "\n";
    }

    @Bean
    ApplicationRunner applicationRunner() {
        System.out.println(Arrays.toString(environment.getActiveProfiles()));
        return args -> {
            System.out.println(a);
            System.out.println(jcjDemoConfig.getA());
        };
    }
}
